﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Hydra.Shell.Attributes;
using System.Collections.Generic;
using Hydra.Shell.Implementations;
using UIObjects;

namespace Hydra.Shell.Interfaces
{
    public class ItemGeneratedEventArgs : EventArgs
    {
        public object Item { get; set; }

        public ItemGeneratedEventArgs()
        {
        }

        public ItemGeneratedEventArgs(object item)
        {
            this.Item = item;
        }
    }

    public class ExceptionEventArgs : EventArgs
    {
        public Exception Exception { get; set; }

        public ExceptionEventArgs()
        {
        }

        public ExceptionEventArgs(Exception ex)
        {
            this.Exception = ex;
        }
    }

    public class ProgressEventArgs : EventArgs
    {
        public float PercentComplete { get; private set; }

        public ProgressEventArgs(float percentComplete)
        {
            this.PercentComplete = percentComplete;
        }
    }

    public delegate void ItemGeneratedHandler(object sender, ItemGeneratedEventArgs e);
    public delegate void ExceptionHandler(object sender, ExceptionEventArgs e);

    public class ItemGenerationOperation
    {
        public event ItemGeneratedHandler Generated;
        public event ExceptionHandler ExceptionOccured;
        public event EventHandler<ProgressEventArgs> OnProgress;
        public Exception Exception { get; set; }

        public ItemGenerationOperation()
        {
        }

        public ItemGenerationOperation(Exception ex)
        {
            this.Exception = ex;
        }

        public bool HasException
        {
            get
            {
                return this.Exception != null;
            }
        }

        public void SetProgress(float percentComplete)
        {
            if (OnProgress != null)
            {
                OnProgress(this, new ProgressEventArgs(percentComplete));
            }
        }

        public void SetGenerated(object sender, object item)
        {
            Generated(sender, new ItemGeneratedEventArgs(item));
        }

        public void SetException(object sender, Exception ex)
        {
            this.Exception = ex;
            ExceptionOccured(sender, new ExceptionEventArgs(ex));
        }
    }


    [Guid("CFF3848F-21E3-4390-BDBB-C6BF0AF2A76E")]
    public interface IHydraUIInternals
    {
        Dictionary<Guid, IProtocolHandlerListItem> ProtocolHandlersList { get; }
        HydraDocumentContainer DocumentContainer { get; }
        HydraDockSite DockSite { get; }
        HandlerLoadOperation LoadProtocolHandler(Guid guidHandler);
        ItemGenerationOperation GenerateAbstraXItemFromID(string id);
        IHydraStatusBar StatusBar { get; }
        UserControl MainPage { get; }
        ILog Log { get; set; }
    }
}
